package colibri.keyboard;


import javax.microedition.lcdui.Canvas;

/**
 *
 * @author Bayron Thiengo Quinelato
 */
public class T9 {

    static final char[] KEY_NUM1_CHARS = new char[]{'.', ',', '?', '!', '1', '@', '\'', '-', '_', '(', ')', ':', ';', '&',
    '\\', '/', '%', '*', '#', '+', '<', '=', '>', '\"', '$'};
    static final char[] KEY_NUM2_CHARS = new char[]{'a', 'b', 'c', '2', 'ã', 'á', 'à', 'â', 'ä'};
    static final char[] KEY_NUM3_CHARS = new char[]{'d', 'e', 'f', '3', 'é', 'ê', 'è', 'ë'};
    static final char[] KEY_NUM4_CHARS = new char[]{'g', 'h', 'i', '4', 'í', 'ì', 'î', 'ï'};
    static final char[] KEY_NUM5_CHARS = new char[]{'j', 'k', 'l', '5'};
    static final char[] KEY_NUM6_CHARS = new char[]{'m', 'n', 'o', '6', 'õ', 'ó', 'ô', 'ò', 'ö'};
    static final char[] KEY_NUM7_CHARS = new char[]{'p', 'q', 'r', 's', '7'};
    static final char[] KEY_NUM8_CHARS = new char[]{'t', 'u', 'v', '8', 'ú', 'ü', 'ù', 'û'};
    static final char[] KEY_NUM9_CHARS = new char[]{'w', 'x', 'y', 'z', '9', 'ý'};
    static final char[] KEY_NUM0_CHARS = new char[]{' ', '0'};

    public static char[] getCharacter(int key) {
        switch (key) {
            case Canvas.KEY_NUM1:
                return KEY_NUM1_CHARS;
            case Canvas.KEY_NUM2:
                return KEY_NUM2_CHARS;
            case Canvas.KEY_NUM3:
                return KEY_NUM3_CHARS;
            case Canvas.KEY_NUM4:
                return KEY_NUM4_CHARS;
            case Canvas.KEY_NUM5:
                return KEY_NUM5_CHARS;
            case Canvas.KEY_NUM6:
                return KEY_NUM6_CHARS;
            case Canvas.KEY_NUM7:
                return KEY_NUM7_CHARS;
            case Canvas.KEY_NUM8:
                return KEY_NUM8_CHARS;
            case Canvas.KEY_NUM9:
                return KEY_NUM9_CHARS;
            case Canvas.KEY_NUM0:
                return KEY_NUM0_CHARS;
            default:
                return null;
        }
    }

    public static char getNumericInteger(int keyCode) {
        if (keyCode >= 48 && keyCode <= 57) {
            return (char) keyCode;
        }
        return 'X';
    }

    public static char getNumericFloat(int keyCode) {
        if (keyCode >= 48 && keyCode <= 57) {
            return (char) keyCode;
        } else if (keyCode == 35) {
            return '.';
        } else if (keyCode == 42) {
            return '-';
        }
        return 'X';
    }

}
